﻿using System;

namespace BankSimulation
{
    public class Account
    {
        private string _accountNumber;
        private decimal _balance;

        public string AccountNumber
        {
            get { return _accountNumber; }
            private set { _accountNumber = value; }
        }

        public decimal Balance
        {
            get { return _balance; }
            protected set { _balance = value; }
        }

        public Account(string accountNumber, decimal initialBalance)
        {
            _accountNumber = accountNumber;
            _balance = initialBalance;
        }

        public virtual void Deposit(decimal amount)
        {
            if (amount > 0)
            {
                Balance += amount;
                Console.WriteLine($"存款成功，当前余额: {Balance}");
            }
            else
            {
                Console.WriteLine("存款金额必须大于0");
            }
        }

        public virtual void Withdraw(decimal amount)
        {
            if (amount > 0 && amount <= Balance)
            {
                Balance -= amount;
                Console.WriteLine($"取款成功，当前余额: {Balance}");
            }
            else
            {
                Console.WriteLine("取款金额无效或余额不足");
            }
        }
    }
}
namespace BankSimulation
{

    public class CreditAccount : Account
    {

        private decimal _creditLimit;

        public decimal CreditLimit
        {
            get { return _creditLimit; }
            private set { _creditLimit = value; }
        }

        public CreditAccount(string accountNumber, decimal initialBalance, decimal creditLimit)
            : base(accountNumber, initialBalance)
        {
            _creditLimit = creditLimit;
        }

 
        public override void Withdraw(decimal amount)
        {
            if (amount > 0 && amount <= Balance + CreditLimit)
            {
                Balance -= amount;
                Console.WriteLine($"取款成功，当前余额: {Balance}");
            }
            else
            {
                Console.WriteLine("取款金额无效或超出信用额度");
            }
        }
    }
}
namespace BankSimulation
{
    // 事件参数类
    public class BigMoneyArgs : EventArgs
    {
        public string AccountNumber { get; }
        public decimal Amount { get; }

        public BigMoneyArgs(string accountNumber, decimal amount)
        {
            AccountNumber = accountNumber;
            Amount = amount;
        }
    }

    public class ATM
    {
        public delegate void BigMoneyFetchedEventHandler(object sender, BigMoneyArgs e);

        public event BigMoneyFetchedEventHandler BigMoneyFetched;
        public void Withdraw(Account account, decimal amount)
        {
            if (amount > 10000)
            {
                OnBigMoneyFetched(account.AccountNumber, amount);
            }

            account.Withdraw(amount);
        }

        protected virtual void OnBigMoneyFetched(string accountNumber, decimal amount)
        {
            BigMoneyFetched?.Invoke(this, new BigMoneyArgs(accountNumber, amount));
        }
    }
}

namespace BankSimulation
{
    class Program
    {
        static void Main(string[] args)
        {
            Account myAccount = new Account("123456789", 50000);
            CreditAccount myCreditAccount = new CreditAccount("987654321", 10000, 5000);

            ATM atm = new ATM();

            atm.BigMoneyFetched += Atm_BigMoneyFetched;


            atm.Withdraw(myAccount, 15000);  // 触发事件
            atm.Withdraw(myCreditAccount, 12000);  // 触发事件
            atm.Withdraw(myAccount, 5000);  // 不触发事件
        }

        private static void Atm_BigMoneyFetched(object sender, BigMoneyArgs e)
        {
            Console.WriteLine($"警告：账户 {e.AccountNumber} 取款 {e.Amount} 元，请注意大额取款！");
        }
    }
}